//
//  SCCertificateIdCardUploadStyleCell.m
//  Shuaiche
//
//  Created by xiangtao on 2024/3/21.
//  Copyright © 2024 ShuaiChe. All rights reserved.
//

#import "SCCertificateIdCardUploadStyleCell.h"
#import "UIImageView+SCwebImage.h"

@implementation SCCertificateIdCardUploadStyleCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.idCardFrontCloseBtn.hidden = YES;
    self.idCardBackCloseBtn.hidden = YES;
    
    self.idCardFrontImageView.layer.cornerRadius = 4;
    self.idCardFrontImageView.layer.masksToBounds = YES;
    self.idCardBackImageView.layer.cornerRadius = 4;
    self.idCardBackImageView.layer.masksToBounds = YES;
    
    self.idCardFrontImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickFrontIdCardAction)];
    [self.idCardFrontImageView addGestureRecognizer:tapGesture];
    
    self.idCardBackImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapBackGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickBackIdCardAction)];
    [self.idCardBackImageView addGestureRecognizer:tapBackGesture];
}

- (void)setFrontModel:(SCCarAddImageItemModel *)frontModel
{
    _frontModel = frontModel;
    if (_frontModel.imageUrlPath) {
        [_idCardFrontImageView sc_setImageWithPath:_frontModel.imageUrlPath];
        _idCardFrontCloseBtn.hidden = NO;
    } else if (_frontModel.image) {
        _idCardFrontImageView.image = _frontModel.image;
        _idCardFrontCloseBtn.hidden = NO;
    } else {
        _idCardFrontImageView.image = [UIImage imageNamed:@"ver_facade.png"];
        _idCardFrontCloseBtn.hidden = YES;
    }
}

- (void)setBackModel:(SCCarAddImageItemModel *)backModel
{
    _backModel = backModel;
    if (_backModel.imageUrlPath) {
        [_idCardBackImageView sc_setImageWithPath:_backModel.imageUrlPath];
        _idCardBackCloseBtn.hidden = NO;
    } else if (_backModel.image) {
        _idCardBackImageView.image = _backModel.image;
        _idCardBackCloseBtn.hidden = NO;
    } else {
        _idCardBackImageView.image = [UIImage imageNamed:@"ver_back.png"];
        _idCardBackCloseBtn.hidden = YES;
    }
}

- (void)clickFrontIdCardAction {
    if (self.delegate && [self.delegate respondsToSelector:@selector(SCCertificateIdCardUploadStyleCellDidAddFrontIdCard)]) {
        [self.delegate SCCertificateIdCardUploadStyleCellDidAddFrontIdCard];
    }
}
- (IBAction)clickFrontCloseAction:(id)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(SCCertificateIdCardUploadStyleCellDidDeleteFrontIdCard)]) {
        [self.delegate SCCertificateIdCardUploadStyleCellDidDeleteFrontIdCard];
    }
}

- (void)clickBackIdCardAction {
    if (self.delegate && [self.delegate respondsToSelector:@selector(SCCertificateIdCardUploadStyleCellDidAddBackIdCard)]) {
        [self.delegate SCCertificateIdCardUploadStyleCellDidAddBackIdCard];
    }
}

- (IBAction)clickBackCloseAction:(id)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(SCCertificateIdCardUploadStyleCellDidDeleteBackIdCard)]) {
        [self.delegate SCCertificateIdCardUploadStyleCellDidDeleteBackIdCard];
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
